#define _CRT_SECURE_NO_WARNINGS
#include "rc4.h"
#include <stdio.h>
#include <string.h>

void PrintHex(unsigned char* strBuff, int len)
{
    for (int i = 0; i < len; i++)
    {
        printf("%02x", strBuff[i]);
    }
    puts("");
}

void RC4Test()
{
    //  f39655b866918cc4c4
    RC4_KEY rc4Key;
    RC4_KEY rc4Key2;
    unsigned char strBuff[16] = { 0 };
    unsigned char userKey[] = "12345678";
    unsigned char strCipherText[1024] = { 0 };
    unsigned char strPlainText[1024] = { 0 };

    strcpy((char*)strBuff, "Hello Rc4");
    Rc4SetKey(&rc4Key, strlen((char*)userKey), userKey);
    Rc4Encrypt(&rc4Key, strlen((char*)strBuff), strBuff, strCipherText);
    PrintHex(strCipherText, strlen((char*)strBuff));

    Rc4SetKey(&rc4Key2, strlen((char*)userKey), userKey);
    Rc4Encrypt(&rc4Key2, strlen((char*)strCipherText), strCipherText, strPlainText);
    PrintHex(strPlainText, strlen((char*)strPlainText));
    printf("%s\r\n", strPlainText);
}

int main()
{
    RC4Test();
    return 0;
}